<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
</head>

<body style="color:#333;padding:3px;" class="x_sorll">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">非常规促销异动</h2>
</div>
<!-- 标题 -->
<div>
    <form action=""  class="form-inline">
        <table class="tab-content table-bordered table" border="1">
            <tr>
                <td>
                    <button class="btn-info btn" type="button" style="margin-right: 15px">导出Excel完整版</button>
                    <button class="btn btn-info">导出Excel打印版</button>
                </td>
            </tr>
        </table>

        <table class="table row-margin-top table-bordered bud_hei">
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">主题</label></td>
                <td colspan="3" class="font-bold">{$data.title}</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">状态</label></td>
                <td>{$data.status_title}</td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">区域纬度</label></td>
                <td colspan="5">{$data.arealat==1?'经销商':'网点'}</td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">产品纬度</label></td>
                <td colspan="5">{$data.productlat_title}</td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">申请人</label></td>
                <td><a href="javascript:;">{$data.cusername}</a></td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">职位</label></td>
                <td>{$data.job}</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">创建时间</label></td>
                <td>{:date('Y-m-d',$data.ctime)}</td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">分区</label></td>
                <td>{$data.zoning}</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">省份</label></td>
                <td>{$data.provice}</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">城市</label></td>
                <td>{$data.city}</td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">经销商名称</label></td>
                <td colspan="3"><span class="font-bold">{$data.jxs_title} <a href="{:url('jxsview',['id'=>$data.jxs_id])}"><span
                        class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true"></span></a></span></td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">性质</label></td>
                <td>经销</td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">编号</label></td>
                <td>{$data.sn}</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">原编号</label></td>
                <td>无</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">修改后编号</label></td>
                <td>无</td>
            </tr>
            <tr>
                <td colspan="6" class="text-left">{$data.brief}
                </td>
            </tr>
        </table>
        <table class="table row-margin-top table-bordered text-center bud_hei" id="table1">

            <tr>
                <th class="font-bold text-center" style="font-size:20px" colspan="33">费用规划内容(金额单位：元)</th>
            </tr>
            <tr class="info">
                <th rowspan="2" class="text-center">状态</th>
                <th rowspan="2" class="text-center">审批人</th>
                <th rowspan="2" class="text-center">序号</th>
                <th rowspan="2" class="text-center">明细编号</th>
                <th rowspan="2" class="text-center">{$data.arealat_title}</th>
                <th rowspan="2" class="text-center">{$data.productlat_title}</th>
                <th rowspan="2" class="text-center">活动执行时间</th>
                <th rowspan="2" class="text-center">异动活动执行时间</th>
                <th rowspan="2" class="text-center">预计核销时间</th>
                <th rowspan="2" class="text-center">三级费用科目</th>
                <th colspan="5" class="text-center">异动前费用详情</th>
                <th colspan="5" class="text-center">异动后费用详情</th>
                <th rowspan="2" class="text-center">费用支付方式</th>
                <th rowspan="2" class="text-center">预计销售</th>
                <th rowspan="2" class="text-center">预计费用率</th>
                <th rowspan="2" class="text-center">2SR基准销量</th>
                <th rowspan="2" class="text-center">基准销量</th>
                <th rowspan="2" class="text-center">预计ROI</th>
                <th rowspan="2" class="text-center">收款方</th>
                <th rowspan="2" class="text-center">备注</th>
                <th rowspan="2" class="text-center">异动原因<span class="colorRed">*</span></th>
            </tr>
            <tr class="info">
                <th class="text-center">未税费用金额</th>
                <th class="text-center">税率</th>
                <th class="text-center">是否增值税(可抵扣)</th>
                <th class="text-center">含税费用金额</th>
                <th class="text-center">实际投入费用</th>
                <th class="text-center">未税费用金额</th>
                <th class="text-center">税率</th>
                <th class="text-center">是否增值税(可抵扣)</th>
                <th class="text-center">含税费用金额</th>
                <th class="text-center">实际投入费用</th>
            </tr>

            <tbody>
            {volist name="data.list" id="row" key="k"}
            <tr data-id="{$row.id}">
                <td>{if $row.status==0}正常{/if}</td>
                <td>无</td>
                <td>{$k}
                    {if $row.ctime>$row.start}
                    <span class="colorRed duigou" title="此单申请时间在活动开始时间之后">补单</span>
                    {/if}
                </td>
                <td>
                    <a href="{:url('dataview',['id'=>$row.id])}">{$data.sn}_{$row.sn}</a>
                    <a href="{:url('decisionbasis',['id'=>''])}">
                            <span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true"
                                  style="display: inline-block;"></span>
                    </a>
                </td>
                <td>
                    {if $row.net_id}{$row.net_title}{else}{$row.jxs_title}<a href="{:url('jxsview',['id'=>$row.jxs_id])}"><span class="glyphicon glyphicon-zoom-in fangda"  aria-hidden="true" style="display: inline-block;"></span>{/if}</a>
                    </td>
                <td>{$row.productlatval}<a href="{:url('roireport')}"><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a></td>
                <td>从{:date('Y-m-d',$row.start)}至{:date('Y-m-d',$row.end)}</td>
                <td>从<input type="text" class="form-control laydate" onclick="var _o = this;laydate({istime: true, format: 'YYYY-MM-DD'})"  style="width: 100px;height: 26px" name="start" value="{:date('Y-m-d',$row.start)}" id="start1"><br>至<input type="text" class="form-control end" onclick="var _o = this;laydate({istime: true, format: 'YYYY-MM-DD',choose: function (datas) {
            /*start.max = datas; //结束日选好后，重置开始日的最大日期
            $('#yjverifyTime').val(GetDateStr(datas,60))*/
            $(_o).closest('tr').find('[name=hexiao]').val(GetDateStr(datas,60))
        }})" style="width: 100px;height: 26px" name="end" value="{:date('Y-m-d',$row.end)}" id="end1"></td>
                <td><input type="text" class="form-control" style="width: 100px;height: 26px" name="hexiao" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" value="{:date('Y-m-d',$row.expCanTime)}"></td>
                <td>{$row.feetype}</td>
                <td class="ObjectNum">{$row.amount}</td>
                <td>{$row.shuilv}%</td>
                <td>{if $row.isVAT==1}是{else}否{/if}</td>
                <td class="ObjectNum">{$row.hanshui}</td>
                <td class="ObjectNum">{$row.fb_shijitourufeiyong}</td>
                <td><input type="text" name="weishui" class="form-control" style="width: 100px;height: 26px" value="{$row.amount}"></td>
                <td><input type="text" name="shuilv" class="form-control" style="width: 60px;height: 26px" value="{$row.shuilv}">%</td>
                <td>
                    <label class="radio-inline">
                        <input type="radio" name="isVAT{$k}"  value="1" {if $row.isVAT==1}checked{/if}>是
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="isVAT{$k}"  value="0" {if $row.isVAT==0}checked{/if}>否
                    </label>
                </td>
                <td class="ObjectNum hanshui">{$row.hanshui}</td>
                <td class="ObjectNum shijitouru">{$row.fb_shijitourufeiyong}</td>
                <td>{$row.paymethod_title}</td>
                <td class="ObjectNum yujixiaoshou">{$row.totalExpectedSales}</td>
                <td class="yujifeilv">{:round($row.hanshui/$row.totalExpectedSales*100,2)}%</td>
                <td class="ObjectNum 2sr">{$row.2srjizhun}</td>
                <td><input type="text" name="basicsales" class="form-control" style="width: 100px;height: 26px" value="{$row.totalBenchmarkSales}"></td>
                <td class="yujiroi">{$row.yujiroi}%</td>
                <td>{if $row.payee==0}(经销商){$row.jxs_title}{else}(供应商){$row.gys_name}{/if}</td>
                <td>{$row.brief}</td>
                <td><input type="text" name="ydreason" class="form-control" style="width: 130px;height: 26px" value=""></td>
            </tr>
            {/volist}
            <tr class="trTotal1 font-bold text-right">
                <td colspan="7">合计</td>
                <td></td>
                <td></td>
                <td></td>
                <td class="ObjectNum">{$data.amounts}</td>
                <td></td>
                <td></td>
                <td class="ObjectNum">{$data.hanshui}</td>
                <td class="ObjectNum">{$data.shijitourufeiyong}</td>
                <td class="ObjectNum">111</td>
                <td></td>
                <td></td>
                <td class="ObjectNum">2500</td>
                <td class="ObjectNum">2500</td>
                <td></td>
                <td class="ObjectNum">{$data.yujixiaoliang}</td>
                <td>{$data.yujifeiyonglv}</td>
                <td class="ObjectNum">{$data.2srjizhun}</td>
                <td class="ObjectNum">{$data.jizhunxiaoliang}</td>
                <td>{$data.yujiroi}%</td>
                <td colspan="3"></td>
            </tr>
            </tbody>
        </table>
        <div class="contact-box">
            <p class="font-bold">
                本申请中包含{if $data.net_cnt}{$data.net_cnt}个网点，{/if}{if $data.brand_cnt}{$data.brand_cnt}个品牌，{/if}{if $data.category_cnt}{$data.category_cnt}个品类，{/if}{if $data.category_cnt}{$data.category_cnt}个品类，{/if}{if $data.series_cnt}{$data.series_cnt}个系列，{/if}{if $data.sku_cnt}{$data.sku_cnt}个sku，{/if}{if $data.product_cnt}{$data.product_cnt}个单品，{/if}{if $data.feetype_cnt}{$data.feetype_cnt}个三级费用科目，{/if}其中路演费:XXX元；调研费:XXX元;总预计费用:{$data.hanshui}元;总预计销量:{$data.yujixiaoliang}元;总预计费用率:{$data.yujifeiyonglv}%;总ROI:{$data.yujiroi}%;
            </p>
        </div>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px;">
            {if isset($attach)}
            <ul class="list-group">
                {volist name="attach" id="row"}
                <li class="list-group-item">
                    <a class="badge badge-primary removeIt" data-id="{$row.id}">移除</a>
                    <a href="{$row.path}" target="_blank">{$row.file_name}</a></li>
                {/volist}
            </ul>
            {/if}
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach">
                <input type="hidden" name="remove" id="remove">
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
    </form>
</div>

{if $data.status==7}
<div class="applyImg font-bold">
    申报已生效
</div>
{elseif $data.status==10}
<div class="SuccessImg font-bold">
    费用已核销
</div>
{/if}
<div class="row sub_btn white-bg" style="width:100%;text-align:center;padding: 20px 0">
    <input type="button" class="btn btn-success save" value="保存为草稿"  id="save1">
    <input type="button" class="btn btn-success save" value="保存并提交工作流" id="save2">
    <input type="button" class="btn btn-warning" value="返回" id="fanhui">
</div>
<!-- 全局js -->
{include file="Public/footer"}

<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
</body>
<script>
    $(function () {

        //输入税率
        $("[name=shuilv]").on('input',function(){
            var shui=0;
            if(!isNaN(parseFloat($(this).val()))){

                shui=parseFloat($(this).val());

            }
            $(this).val(shui);
            var weishui = parseFloat($(this).parent().prev().find('input').val())

            var hanshui = weishui*(1+shui/100)
            $(this).parent().next().next().html(hanshui) //含税费用金额
            $(this).parent().next().next().next().html(hanshui) //实际投入金额
            var yujixiaoshou = $(this).parent().next().next().next().next().next().html() //预计销售

            $(this).parent().next().next().next().next().next().next().html((hanshui/yujixiaoshou*100).toFixed(2)+'%') //预计费用率
        })

        //输入未税费用金额
        $("[name=weishui]").on('input',function(){
            var weishui=0;
            if(!isNaN(parseFloat($(this).val()))){

                weishui=parseFloat($(this).val());

            }
            $(this).val(weishui);
            var shuilv = parseFloat($(this).parent().next().find('input').val())

            var hanshui = weishui*(1+shuilv/100)
            $(this).parent().next().next().next().html(hanshui) //含税费用金额
            $(this).parent().next().next().next().next().html(hanshui) //实际投入金额
            var yujixiaoshou = $(this).parent().next().next().next().next().next().next().html() //预计销售

            $(this).parent().next().next().next().next().next().next().next().html((hanshui/yujixiaoshou*100).toFixed(2)+'%') //预计费用率
        })



        //保存为草稿
        $('.save').on('click',function () {
            var flag = 0
            $("[name=ydreason]").each(function(){
                if($(this).val()!=""){
                    flag=1;
                }
            })
            if(flag==0){
                swal({
                    title: "错误",
                    text:  "至少一条明细发生异动",
                    type: "warning"
                });
            }else {
                var data = []
                $('[name=ydreason]').filter(function () {

                    return $(this).val()!=''

                }).closest('tr').each(function (i,o) {

                    var id = $(o).data('id') //id
                    var start = $(o).find('[name=start]').val() //开始日期
                    var end = $(o).find('[name=end]').val() //结束日期
                    var hexiao = $(o).find('[name=hexiao]').val() //核销
                    var isVAT = $(o).find('[type=radio]:checked').val() //是否VAT
                    var basicsales = $(o).find('[name=basicsales]').val() //基准销量
                    var ydreason = $(o).find('[name=ydreason]').val() //异动原因
                    var weishui = $(o).find('[name=weishui]').val() //未税
                    var shuilv = $(o).find('[name=shuilv]').val() //税率
                    data.push({
                        id:id,
                        start:start,
                        end:end,
                        expCanTime:hexiao,
                        amount:weishui,
                        shuilv:shuilv,
                        isVAT:isVAT,
                        totalBenchmarkSales:basicsales,
                        ydreason:ydreason,
                        hanshui:$(o).find('.hanshui').html(), //税率
                        fb_shijitourufeiyong:$(o).find('.shijitouru').html() //税率
                    })

                })
                var attach = $('#attach').val()
                var remove = $('#remove').val()
                var savetype = $(this).prop('id')
                $.post('',{data:data,attach:attach,remove:remove,type:savetype},function (data) {
                    if(data.success){
                        swal({
                            title:data.msg,
                            type:'success'
                        },function () {
                            location.href='{:url("index")}'
                        })
                    }else
                        swal(data.msg, "", "error");
                },'json')
            }

        })

        //返回
        $('#fanhui').on('click',function () {
            location.href='{:url("index")}'
        })

    })
    function GetDateStr(start,AddDayCount) {
        var dd = new Date(start);
        dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = dd.getMonth()+1;//获取当前月份的日期
        var d = dd.getDate();
        return y+"-"+m+"-"+d;
    }
    
    //输入税率自动计算其他数值
    $('[name=shuilv]').on('input',function () {
        var weishui = $(this).closest('tr').find('[name=weishui]').val()
        var shuilv = $(this).val()
        var hanshui = parseFloat(weishui)*(1+parseFloat(shuilv))
        $(this).closest('td').next('.hanshui').html(hanshui) //含税费用金额
        $(this).closest('td').next('.shijitouru').html(hanshui) //实际投入费用

        $(this).closest('td').next('.yujixiaoshou').html(hanshui) //实际投入费用
    })
</script>

<!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script>
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });

    });
</script>
</html>
